﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace General.Utility
{
    /// <summary>
    /// 工厂类 创建对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public sealed class DataAccess<T> where T : IBase
    {
        private static readonly string datacenterPath = "";
        private static readonly string nameSpace = "";

        private static object lockHelper = new object();
        private static T obj = default(T);

        public static T CreateInstance(DataBaseType type)
        {
            string className = nameSpace + "." + typeof(T).Name.Substring(1);
            if (obj == null)
            {
                lock (lockHelper)
                {
                    //确保只有一个静态实例
                    if (obj == null)
                    {
                        obj = (T)Assembly.Load(datacenterPath).CreateInstance(className);
                    }
                }
            }
            return obj;
        }
    }

    public interface IBase { }

    public enum DataBaseType
    {

    }
}
